@extends('layouts.back_stage')
@section('content')
    <style>
        .towhite:hover,.towhite:focus{
            color:white;
        }
    </style>
            <div class="container">
            <div style="padding:20px 0;"><h3>成本录入</h3></div>
			<div class="container_box">
				<div class="chartshead cost_entry_head">
						<p style="line-height:30px;font-size:13px;">类别选择</p>
						<select class="form-control getType" style="width:130px;height:30px;padding:0 12px;">
                            <option value="">请选择</option>
						</select>
                        <p style="line-height:30px;font-size:13px;">公司</p>
                        <select class="form-control getCompany" style="width:130px;height:30px;padding:0 12px;">
                            <option value="">请选择</option>
                            @foreach($companys as $k=>$v)
                            <option value="{{ $k }}">{{ $v }}</option>
                            @endforeach
                        </select>
						<p style="line-height:30px;font-size:13px;">时间</p>
						<input type="text" readonly style="width: 200px;height:30px;" name="reservation" id="reservation" class="form-control" autocomplete="off" value="" placeholder="选择查询时间" />
                        <button class="btn show_add btn-primary" onclick="show_add()">新增</button>
                        <button class="btn serach_cost btn-info" onclick="serach_cost()">搜索</button>
						<div class="cost_info_box">
							<h6>成本录入</h6>
							<p style="margin-left:1px;float:left;">选择类型</p>
							<select class="form-control cost_id">
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
							</select>
							<span>{{ Auth('admin')->user()->admin_name }}</span>
							<p>录入人</p>
							<table  border="0" cellspacing="0" class="all_income_info">
								<thead>
									<tr>
										<th>金额</th>
										<th>面料商/报销人</th>
										<th>报销日期</th>
                                        <th>公司</th>
										<th>备注</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>

								</tbody>
							</table>
							<button class="btn towhite"  style="float:left;" onclick="add_line()">添加行</button>
							<button class="btn towhite" onclick="remove_add()">关闭</button>

						</div>
				</div>
                <table  border="0" cellspacing="0" style="position: relative;" class="cost_show">
                    <thead>
                    <tr>
                        <th class="col-md-2">金额</th>
                        <th class="col-md-2">面料商/报销人</th>
                        <th class="col-md-2">报销日期</th>
                        <th class="col-md-2">公司</th>
                        <th class="col-md-2">备注</th>
                        <th class="col-md-2">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
                <div class="limit_box" style="position:absolute;top:570px;right:5%;">
                    <button class="btn first_limit live_limit">首页</button>
                    <button class="btn prev_limit live_limit" style="background-color:white;"><</button>
                    <div class="limit_box_limit"></div>
                    <button class="btn next_limit live_limit">></button>
                    <button class="btn last_limit live_limit">尾页</button>
                    <button class="btn pagination_limit" disabled="disabled"></button>
                    <button class="btn data_limit" disabled="disabled"></button>
                </div>
				{{--<div id="single_model"></div>--}}
				{{--<div id="single_month"></div>--}}
				{{--<div class="single_foot">--}}
					{{--<div id="single_foot_pie"></div>--}}
					{{--<div id="single_foot_line"></div>--}}
				{{--</div>--}}
			</div>
            </div>
            <script type="text/javascript">
                $(document).ready(function(){
                    $('#reservation').daterangepicker(null, function(start, end, label) {
                        console.log(start.toISOString(), end.toISOString(), label);
                    });
                });
                    $(".first_limit").hide();
                    $(".last_limit").hide();
                    $(".prev_limit").hide();
                    $(".next_limit").hide();
                    $(".pagination_limit").hide();
                    $(".data_limit").hide();
                    var limit = '';
                    var count = '';
                    var allcount='';
                    var checkend = 0;
                    var resComment = 0;
                    function serach_cost(){       //查询按钮，触发一系列操作
                        var getType = $('.getType option:selected').val();
                        var getCompany = $('.getCompany option:selected').val();
                        var getStart_at = $('#reservation').val().substring(0,10);
                        var getEnd_at = $('#reservation').val().substring(12,23);
                        $(".serach_cost").attr("disabled","disabled");
                        $(".cost_show tbody tr").remove();
                        $(".limit_box_limit").children().remove();
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                            },
                            data:{
                                costing_id:getType,
                                company_id:getCompany,
                                start_at:getStart_at,
                                end_ad:getEnd_at
                            },
                            type:"post",
                            url:"/admin/selectCostingInfo",
                            dataType:'json',
                            success:function(res){
                                if(res.count == 0){
                                    $(".next_limit").attr("disabled","disabled");
                                    $(".last_limit").attr("disabled","disabled");
                                }else{
                                    $(".next_limit").removeAttr("disabled","disabled");
                                    $(".last_limit").removeAttr("disabled","disabled");
                                }
                                console.log(res);
                                limit = res.limit;
                                allcount = res.count;
                                var id ='';
                                for(var i = 0;i < res.data.length;i++){
                                    resComment = res.data[i].comment;
                                    if(resComment == null ||resComment == ""){
                                        $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入' value='空' /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                    }else{
                                        $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入'  value="+res.data[i].comment+ " /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                    }
                                }
                                $(".data_limit").text("共"+res.count+"条数据");
                                count = parseInt(res.count)/5;
                                if(res.count%5 != 0){
                                    var count_num = parseInt(count)+parseInt(1);
                                    checkend = 1;
                                    $(".pagination_limit").text("共"+count_num+"页");
                                    if(count_num > 4){
                                        for(var m = 1;m < 5;m++){
                                            $(".limit_box_limit").append("<button class=\"btn num_limit\">"+m+"</button>");
                                        }
                                    }else{
                                        for(var m = 1;m <= count_num;m++){
                                            $(".limit_box_limit").append("<button class=\"btn num_limit\">"+m+"</button>");
                                        }
                                    }
                                    $(".num_limit").each(function(){
                                        if($(this).text()==1){
                                            $(this).addClass("active")
                                        }
                                    });
                                }else{
                                    var count_num = parseInt(count);
                                    checkend = 0;
                                    $(".pagination_limit").text("共"+count_num+"页");
                                    if(count_num > 4){
                                        for(var m = 1;m < 5;m++){
                                            $(".limit_box_limit").append("<button class=\"btn num_limit\">"+m+"</button>");
                                        }
                                    }else{
                                        for(var m = 1;m <= count_num;m++){
                                            $(".limit_box_limit").append("<button class=\"btn num_limit\">"+m+"</button>");
                                        }
                                    }
                                    $(".num_limit").each(function(){
                                        if($(this).text()==1){
                                            $(this).addClass("active")
                                        }
                                    });
                                }
                                if(limit == 0){
                                    $(".first_limit").attr("disabled","disabled");
                                    $(".prev_limit").attr("disabled","disabled");
                                }
                            }
                        });
                        $(".first_limit").show();
                        $(".last_limit").show();
                        $(".prev_limit").show();
                        $(".next_limit").show();
                        $(".pagination_limit").show();
                        $(".data_limit").show();
                        setTimeout(function(){$(".serach_cost").removeAttr("disabled","disabled");},1000);
                    }
                    $(document).on('click','.next_limit',function(){
                        var getType = $('.getType option:selected').val();
                        var getCompany = $('.getCompany option:selected').val();
                        var getStart_at = $('#reservation').val().substring(0,10);
                        var getEnd_at = $('#reservation').val().substring(12,23);
                        $(".cost_show tbody tr").remove();
                        $(".first_limit").removeAttr("disabled","disabled");
                        $(".prev_limit").removeAttr("disabled","disabled");
                        $(".next_limit").attr("disabled","disabled");
                        $(".num_limit").attr("disabled","disabled");
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                            },
                            data:{
                                costing_id:getType,
                                company_id:getCompany,
                                start_at:getStart_at,
                                end_ad:getEnd_at,
                                limit:parseInt(limit)+parseInt(5)
                            },
                            type:"post",
                            url:"/admin/selectCostingInfo",
                            dataType:'json',
                            success:function(res){
                                $(".next_limit").removeAttr("disabled","disabled");
                                $(".num_limit").removeAttr("disabled","disabled");
                                limit = res.limit;
                                var up_num_limit = parseInt($(".num_limit").siblings().last().text())+1;
                                for(var i = 0;i < res.data.length;i++){
                                    resComment = res.data[i].comment;
                                    if(resComment == null ||resComment == ""){
                                        $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入' value='空' /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                    }else{
                                        $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入'  value="+res.data[i].comment+ " /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                    }
                                }
                                $(".num_limit").removeClass("active");
                                $(".num_limit").each(function(){
                                    if(($(this).text()-1)*5 == limit){
                                        $(this).addClass("active")
                                    }
                                });
                                if(parseInt(limit)+5 >= res.count){
                                    $(".last_limit").attr("disabled","disabled");
                                    $(".next_limit").attr("disabled","disabled");
                                }
                                if(parseInt(limit) >= "15" &&parseInt(limit)%10 ==0 || parseInt(limit) >= "15" &&parseInt(limit)%10 =="5"){
                                    if(parseInt(limit)+5 >= res.count){
                                        console.log("最后一页")
                                    }else{
                                        $(".num_limit").siblings().first().remove();
                                        $(".limit_box_limit").append("<button class=\"btn num_limit\">"+up_num_limit+"</button>");
                                    }
                                }
                            }
                        });
                    });
                    $(document).on('click','.prev_limit',function(){
                        var getType = $('.getType option:selected').val();
                        var getCompany = $('.getCompany option:selected').val();
                        var getStart_at = $('#reservation').val().substring(0,10);
                        var getEnd_at = $('#reservation').val().substring(12,23);
                        $(".cost_show tbody tr").remove();
                        $(".prev_limit").attr("disabled","disabled");
                        $(".num_limit").attr("disabled","disabled");
                        $(".last_limit").removeAttr("disabled","disabled");
                        $(".next_limit").removeAttr("disabled","disabled");
                        var down_num_limit = parseInt($(".num_limit").siblings().first().text())-1;
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                            },
                            data:{
                                costing_id:getType,
                                company_id:getCompany,
                                start_at:getStart_at,
                                end_ad:getEnd_at,
                                limit:parseInt(limit)-parseInt(5)
                            },
                            type:"post",
                            url:"/admin/selectCostingInfo",
                            dataType:'json',
                            success:function(res){
                                $(".prev_limit").removeAttr("disabled","disabled");
                                $(".num_limit").removeAttr("disabled","disabled");
                                limit = res.limit;
                                for(var i = 0;i < res.data.length;i++){
                                    resComment = res.data[i].comment;
                                    if(resComment == null ||resComment == ""){
                                        $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入' value='空' /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                    }else{
                                        $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入'  value="+res.data[i].comment+ " /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                    }
                                }
                                $(".num_limit").removeClass("active");
                                $(".num_limit").each(function(){
                                    if(($(this).text()-1)*5 == limit ){
                                        $(this).addClass("active")
                                    }
                                })
                                if(parseInt(limit) == 0){
                                    $(".first_limit").attr("disabled","disabled");
                                    $(".prev_limit").attr("disabled","disabled");
                                }
                                if(parseInt(limit)%10 ==0 ||parseInt(limit)%10 =="5"){
                                    if(parseInt(limit) == 0 || parseInt(limit)=="5" ||parseInt(limit)=="10"){
                                        console.log("第一页")
                                    }else{
                                        $(".num_limit").siblings().last().remove();
                                        $(".limit_box_limit").prepend("<button class=\"btn num_limit\">"+down_num_limit+"</button>");
                                    }
                                }
                            }
                        });
                    });
                    $(document).on('click','.first_limit',function(){
                        var getType = $('.getType option:selected').val();
                        var getCompany = $('.getCompany option:selected').val();
                        var getStart_at = $('#reservation').val().substring(0,10);
                        var getEnd_at = $('#reservation').val().substring(12,23);
                        $(".cost_show tbody tr").remove();
                        $(".last_limit").removeAttr("disabled","disabled");
                        $(".next_limit").removeAttr("disabled","disabled");
                        $(".first_limit").attr("disabled","disabled");
                        $(".prev_limit").attr("disabled","disabled");
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                            },
                            data:{
                                costing_id:getType,
                                company_id:getCompany,
                                start_at:getStart_at,
                                end_ad:getEnd_at,
                                limit:0
                            },
                            type:"post",
                            url:"/admin/selectCostingInfo",
                            dataType:'json',
                            success:function(res){
                                console.log(res);
                                limit = res.limit;
                                for(var i = 0;i < res.data.length;i++){
                                    resComment = res.data[i].comment;
                                    if(resComment == null ||resComment == ""){
                                        $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入' value='空' /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                    }else{
                                        $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入'  value="+res.data[i].comment+ " /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                    }
                                }
                                if(limit == 0){
                                    $(".num_limit").siblings().remove();
                                    for(var m = 1;m<5;m++){
                                        $(".limit_box_limit").append("<button class=\"btn num_limit\">"+m+"</button>");
                                        $(".num_limit").siblings().first().addClass("active");
                                    }
                                }
                            }
                        });
                        $(".num_limit").siblings().removeClass("active");
                        $(".num_limit").siblings().first().addClass("active")
                    });
                    $(document).on('click','.last_limit',function(){
                        var getType = $('.getType option:selected').val();
                        var getCompany = $('.getCompany option:selected').val();
                        var getStart_at = $('#reservation').val().substring(0,10);
                        var getEnd_at = $('#reservation').val().substring(12,23);
                        $(".cost_show tbody tr").remove();
                        $(".next_limit").attr("disabled","disabled");
                        $(".last_limit").attr("disabled","disabled");
                        $(".first_limit").removeAttr("disabled","disabled");
                        $(".prev_limit").removeAttr("disabled","disabled");
                        console.log(count)
                        if(checkend == 1){
                            $.ajax({
                                headers: {
                                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                },
                                data:{
                                    costing_id:getType,
                                    company_id:getCompany,
                                    start_at:getStart_at,
                                    end_ad:getEnd_at,
                                    limit:(parseInt(count)+ parseInt(1))*5-5
                                },
                                type:"post",
                                url:"/admin/selectCostingInfo",
                                dataType:'json',
                                success:function(res){
                                    console.log(res);
                                    limit = res.limit;
                                    for(var i = 0;i < res.data.length;i++){
                                        resComment = res.data[i].comment;
                                        if(resComment == null ||resComment == ""){
                                            $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入' value='空' /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                        }else{
                                            $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入'  value="+res.data[i].comment+ " /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                        }
                                    }
                                    if(res.count == res.limit){
                                        $(".num_limit").siblings().remove();
                                        if((parseInt(limit)/5)<=3){
                                            for(var m =(parseInt(limit)/5);m>0;m--){
                                                $(".limit_box_limit").prepend("<button class=\"btn num_limit\">"+m+"</button>");
                                                $(".num_limit").siblings().last().addClass("active");
                                            }
                                        }
                                        if((parseInt(limit)/5)>3){
                                            for(var m =(parseInt(limit)/5);m>(parseInt(limit)/5)-3;m--){
                                                $(".limit_box_limit").prepend("<button class=\"btn num_limit\">"+m+"</button>");
                                                $(".num_limit").siblings().last().addClass("active");
                                            }
                                        }
                                    }else{
                                        $(".num_limit").siblings().remove();
                                        if((parseInt(limit)/5)<=3){
                                            for(var m =(parseInt(limit)/5)+1;m>0;m--){
                                                $(".limit_box_limit").prepend("<button class=\"btn num_limit\">"+m+"</button>");
                                                $(".num_limit").siblings().last().addClass("active");
                                            }
                                        }
                                        if((parseInt(limit)/5)>3){
                                            for(var m =(parseInt(limit)/5)+1;m>(parseInt(limit)/5)-3;m--){
                                                $(".limit_box_limit").prepend("<button class=\"btn num_limit\">"+m+"</button>");
                                                $(".num_limit").siblings().last().addClass("active");
                                            }
                                        }

                                    }
                                }
                            });
                            $(".num_limit").siblings().removeClass("active");
                            $(".num_limit").siblings().last().addClass("active")
                        }else{
                            $.ajax({
                                headers: {
                                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                },
                                data:{
                                    costing_id:getType,
                                    company_id:getCompany,
                                    start_at:getStart_at,
                                    end_ad:getEnd_at,
                                    limit:(parseInt(count))*5-5
                                },
                                type:"post",
                                url:"/admin/selectCostingInfo",
                                dataType:'json',
                                success:function(res){
                                    console.log(res);
                                    limit = res.limit;
                                    for(var i = 0;i < res.data.length;i++){
                                        resComment = res.data[i].comment;
                                        if(resComment == null ||resComment == ""){
                                            $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入' value='空' /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                        }else{
                                            $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入'  value="+res.data[i].comment+ " /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                        }
                                    }
                                    if(res.count == res.limit){
                                        $(".num_limit").siblings().remove();
                                        for(var m =(parseInt(limit)/5);m>(parseInt(limit)/5)-3;m--){
                                            console.log(m)
                                            $(".limit_box_limit").prepend("<button class=\"btn num_limit\">"+m+"</button>");
                                            $(".num_limit").siblings().last().addClass("active");
                                        }
                                    }else{
                                        $(".num_limit").siblings().remove();
                                        for(var m =(parseInt(limit)/5)+1;m>(parseInt(limit)/5)-3;m--){
                                            $(".limit_box_limit").prepend("<button class=\"btn num_limit\">"+m+"</button>");
                                            $(".num_limit").siblings().last().addClass("active");
                                        }
                                    }
                                }
                            });
                            $(".num_limit").siblings().removeClass("active");
                            $(".num_limit").siblings().last().addClass("active")
                        }
                    });
                    $(document).on('click','.num_limit',function(){
                        var getType = $('.getType option:selected').val();
                        var getCompany = $('.getCompany option:selected').val();
                        var getStart_at = $('#reservation').val().substring(0,10);
                        var getEnd_at = $('#reservation').val().substring(12,23);
                        var that = this;
                        $(that).attr("disabled","disabled");
                        $(".cost_show tbody tr").remove();
                        limit = ($(this).text()-1)*5;
                        console.log($(this).index());
                        var up_num_limit = parseInt($(this).text())+1;
                        var down_num_limit = parseInt($(this).text())-1;
                        if($(this).index() == 0){
                            if(limit == 0){
                            }else{
                                $(this).siblings().last().remove();
                                $(".limit_box_limit").prepend("<button class=\"btn num_limit\" disabled=\"disabled\">"+down_num_limit+"</button>");
                            }
                        }
                        if($(this).index() == 3){
                            if(parseInt(limit)+5 >= allcount){
                            }else{
                                $(this).siblings().first().remove();
                                $(".limit_box_limit").append("<button class=\"btn num_limit\" disabled=\"disabled\">"+up_num_limit+"</button>");
                            }
                        }
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                            },
                            data:{
                                costing_id:getType,
                                company_id:getCompany,
                                start_at:getStart_at,
                                end_ad:getEnd_at,
                                limit:limit
                            },
                            type:"post",
                            url:"/admin/selectCostingInfo",
                            dataType:'json',
                            success:function(res){
                                console.log(res);
                                limit = res.limit;
                                $(that).removeAttr("disabled","disabled");
                                $(that).siblings().removeAttr("disabled","disabled");
                                for(var i = 0;i < res.data.length;i++){
                                    resComment = res.data[i].comment;
                                    if(resComment == null ||resComment == ""){
                                        $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入' value='空' /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                    }else{
                                        $(".cost_show tbody").append("<tr><td class=\"col-md-2\"><input class=\"cost_money\" readonly=\"readonly\"  type='text' placeholder='点击输入' value="+res.data[i].money+ " /></td><td   class=\"col-md-2\"><input type='text'  class=\"cost_man\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].user_name+" /></td><td class=\"col-md-2\"><input type='date'  class=\"cost_date\" readonly=\"readonly\"  placeholder='点击输入' value="+res.data[i].created_at.substring(0,10)+" /></td><td class=\"col-md-2\">"+res.data[i].company_name+"</td><td class=\"col-md-2\"><input type='text'  class=\"cost_remark\" readonly=\"readonly\"  placeholder='点击输入'  value="+res.data[i].comment+ " /></td><td id=\""+res.data[i].id+"\" class=\"col-md-2\"><button class=\"btn alter towhite\">修改</button></td></tr>");
                                    }
                                }
                                if(limit == 0){
                                    $(".first_limit").attr("disabled","disabled");
                                    $(".prev_limit").attr("disabled","disabled");
                                }
                                if(parseInt(limit)+5 >= res.count){
                                    $(".last_limit").attr("disabled","disabled");
                                    $(".next_limit").attr("disabled","disabled");
                                }
                                if(limit != 0 && parseInt(limit)+5 < res.count){
                                    $(".first_limit").removeAttr("disabled","disabled");
                                    $(".prev_limit").removeAttr("disabled","disabled");
                                    $(".last_limit").removeAttr("disabled","disabled");
                                    $(".next_limit").removeAttr("disabled","disabled");
                                }
                            }
                        });
                        $(this).siblings().removeClass("active");
                        $(this).addClass("active");
                    });
                    $(document).on('click','.alter',function() {
                        var money = $(this).parent().siblings().children(".cost_money").val();
                        var user_name = $(this).parent().siblings().children(".cost_man").val();
                        var costing_id = $('.cost_id').val();
                        var apply_at = $(this).parent().siblings().children(".cost_date").val();
                        var desc = $(this).parent().siblings().children(".cost_remark").val();
                        var that = this;
                        if($(that).text() == "修改"){
                            $(this).parent().siblings().children().removeAttr("readonly");
                            $(this).text("保存");
                            return false;
                        }
                        if($(that).text() == "保存"){
                            $.ajax({
                                headers: {
                                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                },
                                data:{
                                    money:money,
                                    user_name:user_name,
                                    costing_id:costing_id,
                                    apply_at:apply_at,
                                    desc:desc,
                                    id:$(this).parent().attr('id')
                                },
                                type:"post",
                                url:"/finance/updateCostingInfo",
                                dataType:'json',
                                success:function(res){
                                    if(res.success == true){
                                        $(that).text("修改");
                                        $(that).parent().siblings().children().attr("readonly","readonly");
                                    }else{
                                        $(".faceImg").attr("src","/img/weep.png");
                                        $(".oHandle").text("保存失败！请输入内容！");
                                        $(".oSuccess").show(0).delay(1000).hide(0);
                                        return false;
                                    }
                                }
                            });

                        }
                    });
                    function show_add(){
                        $(".cost_info_box").show();
                        $(".all_income_info tbody").append("<tr><td><input class=\"cost_money\" type='text' placeholder='点击输入' /></td><td><input type='text'  class=\"cost_man\" placeholder='点击输入' /></td><td><input  class=\"cost_date jcDate\" placeholder='选择时间' /></td><td><select style=\"width:100%;\" class=\"cost_company form-control\" readonly=\"readonly\"><option value=\"1\">杭州总公司</option><option value=\"2\">河南分公司</option><option value=\"3\">河南分公司2</option></select></td><td><input type='text'  class=\"cost_remark\" placeholder='点击输入' /></td><td><button class='btn alter towhite'>保存</button></td></tr>");
                        $(".all_income_info tbody").append("<tr><td><input class=\"cost_money\" type='text' placeholder='点击输入' /></td><td><input type='text'  class=\"cost_man\" placeholder='点击输入' /></td><td><input  class=\"cost_date jcDate\" placeholder='选择时间' /></td><td><select style=\"width:100%;\" class=\"cost_company form-control\" readonly=\"readonly\"><option value=\"1\">杭州总公司</option><option value=\"2\">河南分公司</option><option value=\"3\">河南分公司2</option></select></td><td><input type='text'  class=\"cost_remark\" placeholder='点击输入' /></td><td><button class='btn alter towhite'>保存</button></td></tr>");
                        $(".all_income_info tbody").append("<tr><td><input class=\"cost_money\" type='text' placeholder='点击输入' /></td><td><input type='text'  class=\"cost_man\" placeholder='点击输入' /></td><td><input  class=\"cost_date jcDate\" placeholder='选择时间' /></td><td><select style=\"width:100%;\" class=\"cost_company form-control\" readonly=\"readonly\"><option value=\"1\">杭州总公司</option><option value=\"2\">河南分公司</option><option value=\"3\">河南分公司2</option></select></td><td><input type='text'  class=\"cost_remark\" placeholder='点击输入' /></td><td><button class='btn alter towhite'>保存</button></td></tr>");
                        $(".all_income_info tbody").append("<tr><td><input class=\"cost_money\" type='text' placeholder='点击输入' /></td><td><input type='text'  class=\"cost_man\" placeholder='点击输入' /></td><td><input  class=\"cost_date jcDate\" placeholder='选择时间' /></td><td><select style=\"width:100%;\" class=\"cost_company form-control\" readonly=\"readonly\"><option value=\"1\">杭州总公司</option><option value=\"2\">河南分公司</option><option value=\"3\">河南分公司2</option></select></td><td><input type='text'  class=\"cost_remark\" placeholder='点击输入' /></td><td><button class='btn alter towhite'>保存</button></td></tr>");
                        $(".all_income_info tbody").append("<tr><td><input class=\"cost_money\" type='text' placeholder='点击输入' /></td><td><input type='text'  class=\"cost_man\" placeholder='点击输入' /></td><td><input  class=\"cost_date jcDate\" placeholder='选择时间' /></td><td><select style=\"width:100%;\" class=\"cost_company form-control\" readonly=\"readonly\"><option value=\"1\">杭州总公司</option><option value=\"2\">河南分公司</option><option value=\"3\">河南分公司2</option></select></td><td><input type='text'  class=\"cost_remark\" placeholder='点击输入' /></td><td><button class='btn alter towhite'>保存</button></td></tr>");
                        $(function (){
                            $(".jcDate").jcDate({
                                IcoClass : "jcDateIco",
                                Event : "click",
                                Speed : 100,
                                Left : 0,
                                Top : 28,
                                format : "-",
                                Timeout : 5000
                            });
                        });
                        $('.alter').click(function(){
                            var money = $(this).parent().siblings().children(".cost_money").val();
                            var user_name = $(this).parent().siblings().children(".cost_man").val();
                            var company_id = $(this).parent().siblings().children(".cost_company").val();
                            var costing_id = $('.cost_id').val();
                            var apply_at = $(this).parent().siblings().children(".cost_date").val();
                            var desc = $(this).parent().siblings().children(".cost_remark").val();
                            if($(this).text() == "保存"){
                                if(money == "" || user_name == "" || apply_at==""){
                                    $(".faceImg").attr("src","/img/weep.png");
                                    $(".oHandle").text("请输入内容");
                                    $(".oSuccess").show(0).delay(1000).hide(0);
                                    return false;
                                }
                                if(!(/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(money))){
                                    $(".faceImg").attr("src","/img/weep.png");
                                    $(".oHandle").text("金额格式不正确");
                                    $(".oSuccess").show(0).delay(1000).hide(0);
                                    return false;
                                }
                                if(!(/^([a-zA-Z0-9_\u4e00-\u9fa5]){2,16}$/.test(user_name))){
                                    $(".faceImg").attr("src","/img/weep.png");
                                    $(".oHandle").text("格式名称不正确");
                                    $(".oSuccess").show(0).delay(1000).hide(0);
                                    return false;
                                }
                                $.ajax({
                                    headers: {
                                        'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                    },
                                    data:{
                                        money:money,
                                        user_name:user_name,
                                        company_id:company_id,
                                        costing_id:costing_id,
                                        apply_at:apply_at,
                                        desc:desc
                                    },
                                    type:"post",
                                    url:"/finance/addCostingInfo",
                                    dataType:'json',
                                    success:function(res){
                                        console.log(res);
                                    }
                                });
                                $(this).parent().siblings().children().attr("readonly","readonly");
                                $(this).parent().siblings().children().attr("disabled","disabled");
                                $(this).text('完成');
                            }
                        });
                    }
                    function remove_add(){
                        $(".cost_info_box").hide();
                        $(".all_income_info tbody tr").remove();
                        serach_cost();
                    }
                    function add_line(){
                        $(".all_income_info tbody").append("<tr><td><input class=\"cost_money\" type='text' placeholder='点击输入' /></td><td><input type='text'  class=\"cost_man\" placeholder='点击输入' /></td><td><input  class=\"cost_date jcDate\" placeholder='选择时间' /></td><td><select  style=\"width:100%;\" class=\"cost_company form-control\" readonly=\"readonly\"><option value=\"1\">杭州总公司</option><option value=\"2\">河南分公司</option><option value=\"3\">河南分公司2</option></select></td><td><input type='text'  class=\"cost_remark\" placeholder='点击输入' /></td><td><button class='btn alter towhite'>保存</button></td></tr>");
                        $(function (){
                            $(".jcDate").jcDate({
                                IcoClass : "jcDateIco",
                                Event : "click",
                                Speed : 100,
                                Left : 0,
                                Top : 28,
                                format : "-",
                                Timeout : 5000
                            });
                        });
                        $('.alter').click(function(){
                            var money = $(this).parent().siblings().children(".cost_money").val();
                            var user_name = $(this).parent().siblings().children(".cost_man").val();
                            var company_id = $(this).parent().siblings().children(".cost_company").val();
                            var costing_id = $('.cost_id').val();
                            var apply_at = $(this).parent().siblings().children(".cost_date").val();
                            var desc = $(this).parent().siblings().children(".cost_remark").val();
                            $.ajax({
                                headers: {
                                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                },
                                data:{
                                    money:money,
                                    user_name:user_name,
                                    company_id:company_id,
                                    costing_id:costing_id,
                                    apply_at:apply_at,
                                    desc:desc
                                },
                                type:"post",
                                url:"/finance/addCostingInfo",
                                dataType:'json',
                                success:function(res){
                                    console.log(res)
                                }
                            });
                            $(this).parent().siblings().children().attr("readonly","readonly");
                            $(this).text('完成');
                        });
                    }
            </script>
@endsection
@section('style')
    @parent
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/daterangepicker-bs3.css" rel="stylesheet">
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/jcDate.css" rel="stylesheet">
@endsection
@section('script')
    @parent
        {{--<script src="{{ env('CDN_DOMAIN_NAME') }}/js/jquery-1.10.2.js" type="text/javascript"></script>--}}
        {{--<script src="{{ env('CDN_DOMAIN_NAME') }}/js/bootstrap.min.js" type="text/javascript"></script>--}}
        <script src="{{ env('CDN_DOMAIN_NAME') }}/js/echarts.common.min.js" type="text/javascript"></script>
        <script src="{{ env('CDN_DOMAIN_NAME') }}/js/moment.js" type="text/javascript"></script>
        <script src="{{ env('CDN_DOMAIN_NAME') }}/js/daterangepicker.js" type="text/javascript"></script>
        <script src="{{ env('CDN_DOMAIN_NAME') }}/js/jQuery-jcDate.js" type="text/javascript"></script>
        <script src="https://www.jq22.com/jquery/jquery-migrate-1.2.1.min.js"></script><!--JQ的版本引导-->

@endsection

